package example01;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test01 {
	public static void main(String[] args) {
		String strInput = "Hello every body";
		String strSearch = "Hello";
		String strReplace = "Good bye";
		
		Pattern pattern = Pattern.compile(strInput);
		Matcher matcher = pattern.matcher(strInput);
		
		while(matcher.find()) {
			int s = matcher.start();
			int e = matcher.end();
			
			String replace = strInput.substring(s, e);
			System.out.println("Matched: " + replace);
		}
		
		String strOutput = matcher.replaceAll(strReplace);
		
		System.out.println("Input: " + strInput);
		System.out.println("Output: " + strOutput);
		
		System.out.println("matches: "+ matcher.matches());
		System.out.println("lookingAt: " + matcher.lookingAt());
	}

}
